#define _CRT_SECURE_NO_WARNINGS	

#include<stdio.h>

void swap(int* x, int* y)
{
    int tmp = *x;
    *x = *y;
    *y = tmp;
}

void reverse(int* arr, int x, int y)
{
    while (x < y)
    {
        swap(&arr[x], &arr[y]);
        x++;
        y--;
    }
}

int Find(int* nums, int numsSize, int target, int step)
{
    if (target < nums[0])
        return -1;
    if (target > nums[numsSize - 1])
        return -1;
    int left = 0;
    int right = numsSize - 1;
    int dex = -1;
    while (left <= right)
    {
        int mid = (left + right) / 2;
        if (nums[mid] == target)
        {
            dex = mid;
            break;
        }
        else if (nums[mid] > target)
            right = mid - 1;
        else
            left = mid + 1;
    }
    if (dex == -1)
        return -1;
    else
        return (dex >= step) ? dex - step : numsSize + dex - step;
}

int search(int* nums, int numsSize, int target)
{
    int i;
    for (i = 1; i < numsSize; i++)
    {
        if (nums[i] < nums[i - 1])
            break;
    }
    int step = numsSize - i;
    reverse(nums, 0, i - 1);
    reverse(nums, i, numsSize - 1);
    reverse(nums, 0, numsSize - 1);
    return Find(nums, numsSize, target, step);
}

int main()
{
    int nums[10] = { 1 };
    int numsSize = 1;
    int target = 1;
    printf("%d", search(nums,numsSize, target));
}